/* filename: def28x.h */
/* By RealSYS	2003/10/23 */

#ifndef	__DEF28X_H
#define	__DEF28X_H

/* define constants */
#define FALSE	0
#define TRUE	!FALSE
#define	NULL	(void *)0
#define HIGH	1
#define LOW		0
#define LF		0x0A	// Line feed
#define CR		0x0D	// Carrage return

typedef	char	        BOOL;
typedef	unsigned char	BYTE;
typedef	unsigned int	WORD;
typedef	unsigned long	LONG;

#define	NOP		asm("	NOP")
#define	EI		asm("	clrc INTM")
#define	DI		asm("	setc INTM")

#define	HI_BYTE(val)		((val>>8)&0xff)
#define	LO_BYTE(val)		(val&0xff)

#define	BIT_MASK(x)			(1 << (x))
#define GetBit(val, bit)	(((val) & BIT_MASK(bit))>>(bit))
#define	SetBit(val, bit)	((val) |= BIT_MASK(bit))
#define	ClearBit(val, bit)	((val) &= ~BIT_MASK(bit))
#define	ToggleBit(val, bit)	((val) ^=BIT_MASK(bit))

#define	CHK_BIT(x, bit)		((x) & (bit))
#define	SET_BIT(x, bit)		((x) |= (bit))
#define	CLR_BIT(x, bit)		((x) &= ~(bit))
#define	HI_BIT(x, bit)		((x) |= (bit))
#define	LO_BIT(x, bit)		((x) &= ~(bit))
#define	TOGGLE_BIT(x, bit)	((x) ^= (bit))

#define DELAY_1us			asm(" RPT #146 || NOP ");	/* 6.667ns * 150 = 1usec */

#define	READ_XDATA(a)	 	*(WORD *)(a)
#define	WRITE_XDATA(a,d) 	*(WORD *)(a) = d

#define COMA    0x2000
#define IERA    0x2001
#define IIRA    0x2002   //read
#define FCRA    0x2002   //write  
#define LCRA    0x2003
#define MCRA    0x2004
#define LSRA    0x2005
#define MSRA    0x2006
#define SPRA    0x2007
/* Enhanced function register */
#define DLLA    0x2000
#define DLHA    0x2001
#define EFRA    0x2002
#define TCRA    0x2006
#define TLRA    0x2007
#define FRRA    0x2007

#define COMB    0x2100
#define IERB    0x2101
#define IIRB    0x2102   //read
#define FCRB    0x2102   //write  
#define LCRB    0x2103
#define MCRB    0x2104
#define LSRB    0x2105
#define MSRB    0x2106
#define SPRB    0x2107
/* Enhanced function register */
#define DLLB    0x2100
#define DLHB    0x2101
#define EFRB    0x2102
#define TCRB    0x2106
#define TLRB    0x2107
#define FRRB    0x2107

#define COMC    0x2200
#define IERC    0x2201
#define IIRC    0x2202   //read
#define FCRC    0x2202   //write
#define LCRC    0x2203
#define MCRC    0x2204
#define LSRC    0x2205
#define MSRC    0x2206
#define SPRC    0x2207
/* Enhanced function register */
#define DLLC    0x2200
#define DLHC    0x2201
#define EFRC    0x2202
#define TCRC    0x2206
#define TLRC    0x2207
#define FRRC    0x2207

#define COMD    0x2300
#define IERD    0x2301
#define IIRD    0x2302   //read
#define FCRD    0x2302   //write  
#define LCRD    0x2303
#define MCRD    0x2304
#define LSRD    0x2305
#define MSRD    0x2306
#define SPRD    0x2307
/* Enhanced function register */
#define DLLD    0x2300
#define DLHD    0x2301
#define EFRD    0x2302
#define TCRD    0x2306
#define TLRD    0x2307
#define FRRD    0x2307

#endif
